package com.rabbiter.market.controller.admin.system.menu;

import com.rabbiter.market.common.sercurity.annotation.HasPermisson;
import com.rabbiter.market.common.web.response.JsonResult;
import com.rabbiter.market.domain.system.menu.Menu;
import com.rabbiter.market.qo.system.MenuQuery;
import com.rabbiter.market.service.system.menu.IMenuService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/menu")
public class MenuController {
    @Autowired
    private IMenuService menuService;

    /**
     * 条件分页查询菜单的信息
     * @param qo
     * @return
     */
    @HasPermisson("system:menu:list")
    @PostMapping("/queryPageByQo")
    public JsonResult queryPageByQo(MenuQuery qo) {
        Page<Menu> page = menuService.queryPageByQo(qo);
        return JsonResult.success(page);
    }

    /**
     * 新增菜单
     * @param menu
     * @return
     */
    @PostMapping("/addMenu")
    public JsonResult addMenu(Menu menu) {
        menuService.addMenu(menu);
        return JsonResult.success();
    }

    /**
     * 删除菜单
     * @param id
     * @return
     */
    @DeleteMapping("/deleteMenu/{id}")
    public JsonResult deleteMenu(@PathVariable Long id) {
        menuService.deleteMenu(id);
        return JsonResult.success();
    }

    /**
     * 修改菜单
     * @param menu
     * @return
     */
    @PostMapping("/editMenu")
    public JsonResult editMenu(@RequestBody Menu menu) {
        menuService.editMenu(menu);
        return JsonResult.success();
    }
}
